package com.magicsoft.share.presenter.share;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.share.CommentList;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.view.share.ICommentListView;

import io.reactivex.annotations.NonNull;

/**
 * Created by lyf on 2017/11/28/028.
 */

public class CommentListPresenter extends BasePresenter<ICommentListView> {
    public void  commentList(long articleId,int pageNum,int pageSize){
        RetrofitUtil.getApi(APIService.class)
                .commentList( articleId,pageNum,pageSize)
                .compose(new NetWorkTransformer<CommentList>())
                .compose(new LoadingTransformer<CommentList>(mContext))
                .subscribe(new SimpleObserver<CommentList>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull CommentList commentList) {

                        getView().commentListSuccess(commentList);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().commentListFail();
                    }
                });
    }
}
